extends Node2D

@onready var state_bar = $VBoxContainer/StateBar
var state 
var placeholder

func _ready():
	state = Globals.player_state
	$VBoxContainer/HPLabel.set_text(str(state.health))
	$VBoxContainer/AngerLabel.set_text(str(state.anger))
	$AnimatedSprite2D.sprite_frames = state.act_sprite_frames
	if not state.state_changed.is_connected(update_state):
		state.state_changed.connect(update_state)


func update_state(type:StateBar.STATE = StateBar.STATE.NOTHING, value = 0, duration = 0) -> void:
	$VBoxContainer/HPLabel.set_text(str(state.health))
	$VBoxContainer/AngerLabel.set_text(str(state.anger))
	state_bar.state_match(type, value, duration)
	
func play_animation(s):
	$AnimatedSprite2D.play(s)


func before_round():
	state.next_point = 0
	state_bar.before_round(state)


func after_round():
	state_bar.after_round(state)


func take_damage(damage):
	state.take_damage(damage)
	if state.health <= 0:
		self.queue_free()
		
func heal(amount: int) -> void:
	Shake.show_number(self, amount, Color.LIME_GREEN)
	state.heal(amount)
